﻿using B.S.Ingredients.APIWrite.Applications.Command;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIWrite.Applications.CommandHandler
{
    public class ProductCreateCommandHandler : IRequestHandler<ProductCreateCommand, APIResult<int>>
    {
        public ProductCreateCommandHandler(IBaseRepository<Product> repository)
        {
            Repository = repository;
        }

        public IBaseRepository<Product> Repository { get; }

        public async Task<APIResult<int>> Handle(ProductCreateCommand request, CancellationToken cancellationToken)
        {
            request.Data.CreateName = "张三";
            request.Data.CreateTime = DateTime.Now;
             var path= await Repository.CreateAsync(request.Data);
            return new APIResult<int>()
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path
            };
        }
    }
}
